/**
 * 
 */
package dms.presentation.form.supervisor;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

import dms.dto.DormSupervisorDTO;
import dms.model.role.wrapper.DormSupervisorWrapper;
import dms.util.ContextUtil;
import dms.util.PasswordUtil;

/**
 * @author 李健
 *
 */
public class ModifyInfoForm extends DormSupervisorDTO {
	@Override
	public ActionErrors validate(ActionMapping arg0, HttpServletRequest request) {
		ActionErrors errors = new ActionErrors();
		
		DormSupervisorWrapper wrapper = (DormSupervisorWrapper) ContextUtil.getContext().getBean("dormSupervisorWrapper");
		String email = wrapper.getDormSupervisor().getAccount().getEmail();
		String password = wrapper.getDormSupervisor().getAccount().getPassword();
		if(this.oldEmail != null && email != null) {
			if (this.oldEmail.length() > 0 && this.email.length() > 0) {
				if (!this.oldEmail.equals(email)) {
					errors.add("error", new ActionMessage("邮件地址填写有误", false));
				}
			}
		}
			
		if (this.oldPassword != null && this.password != null) {		
			if (this.oldPassword.length() > 0 && this.password.length() > 0) {
				String oldPassword = PasswordUtil.MD5Digest(this.oldPassword); 
				if (!oldPassword.equals(password)) {
					errors.add("error", new ActionMessage("密码不一致", false));
				}
			}
		}
			
		return errors;
	}
}
